<template>
	<view class="content">
		<view class="wid100" style="height: 468rpx;">
			<image :src="url+'/addon/qianyu_petrol/wxapp/image/tu4.png'" class="wh100"></image>
		</view>
		<view class="wid90 mar bacFFF borRad20" style="border: 4px solid #FFC943;padding: 40rpx 0;">
			<view class="wid80 mar">
				<view class="textCen" style="color: #FA4928;font-size: 45rpx;">-我的邀请战绩-</view>
				<view class="dis disAl disJuB fowe600 " style="margin-top: 65rpx;">
					<view class="textCen">
						<view class="foSi40" style="color: #FF6724;">{{count}}</view>
						<view class="mar-top20 foSi25">邀请好友</view>
					</view>
					<view class="textCen">
						<view class="foSi40" style="color: #FF6724;">{{divide_integral}}</view>
						<view class="mar-top20 foSi25">获得积分</view>
					</view>
					<view class="textCen">
						<view class="foSi30" style="vertical-align: bottom;color: #FF6724;">
							<span>¥</span>
							<span class="fowe600 foSi40">{{divide_money}}</span>
						</view>
						<view class="mar-top20 foSi25">获得奖励</view>
					</view>
				</view>
				<view class="hei80 dis disAl disJuC coFFF foSi35 borRad40" @click="tiaozhuan('/pages/referrer/invitation')"
					style="background-color: #FE6522;margin-top: 58rpx;">查看邀请详情</view>
			</view>
		</view>
		<view class="wid90 mar bacFFF borRad20 mar-top20" style="border: 4px solid #FFC943;padding: 30rpx 0;">
			<view class="wid85 mar">
				<view class="textCen" style="color: #FA4928;font-size: 45rpx;">-活动说明-</view>
				<view class="foSi25 mar-top30" style="line-height: 41rpx;">
					<rich-text :nodes="content"></rich-text>
					<!-- <view>1、只有未注册过的好友才能领取优惠券 </view>
					<view>2、奖励金计算方法（好友消费金额-优惠金额）×10% 举例如果好友领取10元优惠券后到店</view> -->
				</view>
			</view>
		</view>
		<view class="wid90 mar bacFFF borRad20 mar-top20" style="border: 4px solid #FFC943;padding: 30rpx 0;">
			<view class="wid85 mar">
				<view class="textCen" style="color: #FA4928;font-size: 45rpx;">-邀请排行榜-</view>
				<view class="dis disAl disJuB foSi25 mar-top30">
					<view>奖励排行</view>
					<view>获得奖励金</view>
				</view>
				<block v-for="(item,index) in list" :key="index">
					<view class="dis disAl disJuB mar-top20 foSi25">
						<view class="dis disAl">
							<view class="textCen" style="width: 50rpx;">{{index+1}}</view>
							<image :src="url+item.avatar" style="width: 40rpx;height: 40rpx;" class="borRad50 mar-right10"></image>
							<view>{{item.nickname}}</view>
						</view>
						<view>¥{{item.rewards_all}}</view>
					</view>
				</block>
			</view>
		</view>
		<view v-if="userinfo" class="wid100 dis disJuC mar-top40">
			<!-- <view class="dis disAl disJuC borRad40 foSi40 bacFFF fowe600"
				style="width: 524rpx;height: 82rpx;color: #FE6522;">立即邀请好友</view> -->
			<button class="dis disAl disJuC borRad40 foSi40 bacFFF fowe600" open-type="share" 
				style="width: 524rpx;height: 82rpx;color: #FE6522;">立即邀请好友</button>
		</view>
		<view style="height: 70rpx;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				list: [],
				count: 0,
				divide_money: 0,
				divide_integral: 0,
				rewards: 0,
				userinfo: '',
				content:''
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo')
			this.getList()
		},
		onShow() {},
		// 自定义此页面的转发给好友(已经有全局的分享方法，此处会覆盖全局)
		onShareAppMessage(res) {
			var that = this;
			var userinfo = uni.getStorageSync('userinfo')
			var imageUrl = this.url + '/addon/qianyu_petrol/wxapp/image/header.png'
			if(userinfo.avatar){
				imageUrl = this.url+this.userinfo.avatar
			}
			that.dingyue()
			return {
				title: '惠易油',
				path: '/pages/index/index?parent_id=' + this.userinfo.id,
				imageUrl: imageUrl
			}
		},
		methods: {
			dingyue() {
				var that = this
				// 要检查的订阅id
				let id = uni.getStorageSync('tzId').invite_success_template
				let id1 = uni.getStorageSync('tzId').reward_received_template
				// 这里是获取下发权限地方，根据官方文档，可以根据  wx.getSetting() 的 withSubscriptions   这个参数获取用户是否打开订阅消息总开关。后面我们需要获取用户是否同意总是同意消息推送。所以这里要给它设置为true 。
				wx.getSetting({
					withSubscriptions: true, //  这里设置为true,下面才会返回mainSwitch
					success: function(res) {
						// 调起授权界面弹窗
						// if (res.subscriptionsSetting.mainSwitch) { // 用户打开了订阅消息总开关
						// 	if (res.subscriptionsSetting.itemSettings == null) {
								// 当用户没有点击 ’总是保持以上选择，不再询问‘  按钮。那每次执到这都会拉起授权弹窗
								wx.showModal({
									title: '提示',
									content: '请授权开通服务通知',
									showCancel: true,
									success: function(ress) {
										if (ress.confirm) {
											wx.requestSubscribeMessage({ // 调起消息订阅界面
												tmplIds: [id,id1],
												success(res) {
													console.log('订阅消息 成功 ');
													console.log(res);
												},
												fail(er) {
													console.log("订阅消息 失败 ");
													console.log(er);
												}
											})
										}
									}
								})
							}
					// 	}
					// },
					// fail: function(error) {
					// 	console.log(error);
					// },
				})
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_user_son_list',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.count = result.data.count
							that.divide_money = result.data.divide_money
							that.divide_integral = result.data.divide_integral
							that.rewards = result.data.rewards
							that.list = result.data.rank_list
							that.content = result.data.content
						}
					}
				})
			},
			tiaozhuan(url) {
				if(!this.userinfo){
					uni.switchTab({
						url: '/pages/wode/wode'
					})
				}else{
					uni.navigateTo({
						url: url
					})
				}
			}
		}
	}
</script>

<style>
	.content {
		background: #FE6522;
		min-height: 100vh;
	}
</style>
